<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3" xmlns:head="http://www.w3.org/1999/html">
<head th:include="public/public_css::public_css ('人工驱动补货管理')"/>

<body style="background-color: #f2f2f2;">
<div class="layui-fluid larry-wrapper">
    <div class="layui-card">
        <div class="layui-row layui-col-space30">
            <div class="layui-col-xs24">
                <form class="layui-form layui-card-header  layui-card-header-auto" id="searchForm">

                    <div class="layui-inline">
                        <label class="layui-form-label">补货单号</label>
                        <div class="layui-input-inline">
                            <input type="text" class="layui-input" id="bh" name="bh" placeholder="补货单号"/>
                        </div>
                    </div>


                    <div class="layui-inline">
                        <label class="layui-form-label">创建时间</label>
                        <div class="layui-input-inline">
                            <input type="text" class="layui-input" id="cjsj" name="cjsj" placeholder="yyyy-MM-dd HH:mm:ss"/>
                        </div>
                    </div>

                    <div class="layui-inline">
                        <label class="layui-form-label">补货状态</label>

                        <select name="zt" id="ztSelect" lay-search>
                        </select>
                    </div>




                    <div class="layui-inline inline-search-btn">
                        <a class="layui-btn layui-btn-normal" data-type="reload">查询</a>
                    </div>
                </form>
                <div class="moreBtn"><i class="layui-icon layui-icon-triangle-d" style="color: #1E9FFF;"></i></div>
                <div class="group-button" id="toolbar">
                    <a class="layui-btn layui-btn-sm layui-btn-normal " id="add-btn">
                        <i class="layui-icon">&#x1005;</i> 新增
                    </a>
                    <a class="layui-btn layui-btn-sm layui-btn-normal " id="dao-btn">
                        <i class="layui-icon">&#x1005;</i> 多选导出
                    </a>
                    <a class="layui-btn layui-btn-sm layui-btn-danger " id="del-btn">
                        <i class="layui-icon">&#x1005;</i> 多选删除
                    </a>

                    <!-- Single button -->
                    <!--<div class="btn-group">-->
                        <!--<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown"-->
                                <!--aria-haspopup="true" aria-expanded="false">-->
                            <!--多选操作 <span class="caret"></span>-->
                        <!--</button>-->
                        <!--&lt;!&ndash;<ul class="dropdown-menu">&ndash;&gt;-->
                            <!--&lt;!&ndash;<li><a id="btn_jin" href="#">批量禁用</a></li>&ndash;&gt;-->
                            <!--&lt;!&ndash;<li><a id="btn_qi" href="#">批量启用</a></li>&ndash;&gt;-->
                        <!--&lt;!&ndash;</ul>&ndash;&gt;-->
                    <!--</div>-->
                </div>
                <!--列表-->
                <section class="panel panel-padding layui-card-body">
                    <div class="pro">
                        <table id="table"></table>
                    </div>
                </section>
            </div>
        </div>
    </div>
</div>

</body>


<div th:include="/public/public_js::public_js"></div>
<style type="text/css">
    .moreBtn {
        width: 50px;
        height: 20px;
        text-align: center;
        color: #fff;
        line-height: 20px;
        background-color: #eee;
        position: relative;
        margin: 0 auto;
        cursor: pointer;
    }

    .moreBtn:before {
        content: '';
        display: block;
        width: 35px;
        height: 20px;
        position: absolute;
        transform: skewX(30deg);
        background: #eee;
        border-top-left-radius: 8px;
        left: -20px;
        top: 0;
    }

    .moreBtn:after {
        content: '';
        display: block;
        width: 35px;
        height: 20px;
        position: absolute;
        transform: skewX(-30deg);
        background: #eee;
        border-top-right-radius: 8px;
        top: 0;
        right: -20px;
    }
</style>
<script>

    $(function () {
        $(".moreBtn").on("click",function () {
            $(".moreSearch").toggle();
        });


    });


    layui.use(['list', 'layer', 'zzpUtils', 'jquery', 'laydate'], function () {
        window.operateEvent = {
            "click .layui-btn-primary": function (e, value, row, index) {
                /*这里激活状态那个按钮用不到，啥都不需要写，只读*/
            },
            "click #editRow": function (e, value, row, index) {//行按钮编辑  btn_stop
                editDialog(row.id, row.jhzt);
            },
            "click #btn_jin": function (e, value, row, index) {//行按钮禁用
                stopDialog(row.id);
            },
            "click #btn_qi": function (e, value, row, index) {//行按钮启用
                startDialog(row.id);
            }



        }






        var zzpUtils = layui.zzpUtils,
            $ = layui.jquery,
            laydate = layui.laydate;

        //
        function editDialog(id, hpzt) {

                zzpUtils.dialog({
                    title: "修改货品种类",
                    type: 2,
                    content: "/SendReceiveCategory/editCategory?id=" + id,
                    area: ['50%', '50%'], //设置dialog大小，也可以不设置，
                    end: function () {//修改成功后刷新
                        zzpUtils.refreshTable("#table");
                    }
                });

        }
        //查询字典表中的数据 订单类型
        zzpUtils.select({
            elem:"#ztSelect",    //dom
            url:"/sysdictionary/getSysdictionary/wms_artificial_replenishment_zt"
            //路径 以"/"开头，后边正常字典路径
        });

        $("#dao-btn").on("click",function(){
            alert(123);

            var arr=[];
            var $rows = $table.bootstrapTable('getSelections');
            if ($rows.length >0) {
                arr = $.map($rows, function (row) {
                    return row.id;
                })
            }
            var  ids ;
            // console.log(123);
            //  var $rows = $table.bootstrapTable('getSelections');
            //  if ($rows.length == 1) {
            //      var ids = $.map($rows, function (row) {
            //          return row.id;
            //      })
            //  }

            var xhr = new XMLHttpRequest();
            xhr.open("POST", "http://localhost:8080/zxsdwms/wmsartificialreplenishment/getOutPutList", true);
            xhr.responseType = "blob";
            xhr.setRequestHeader('Accept', 'application/json');
            xhr.setRequestHeader('Content-Type', 'application/json');
            xhr.setRequestHeader('Charset', 'utf-8');
            xhr.onload = function() {
                if (this.status == 200) {
                    var name = xhr.getResponseHeader("Content-disposition");
                    name=decodeURI(name);
                    var filename = name.substring(20,name.length);
                    var blob = new Blob([xhr.response], {type: 'text/xls'});
                    var csvUrl = URL.createObjectURL(blob);
                    var link = document.createElement('a');
                    link.href = csvUrl;
                    link.download = filename;
                    link.click();
                }
            };
            var str=zzpUtils.getFormJson($("#searchForm"));
            var object2 = Object.assign({ids: arr}, str);
            /*将条件查询和ids传到后台*/
            xhr.send(JSON.stringify(
                object2
            ));

        })  ;// 导出结束

        laydate.render({
            elem: '#cjsj'
            , theme: '#20a0ff',
            range:true
        });

        //多选删除
        $("#del-btn").on("click",function(){
            alert(123);
            var ids=[];
            var $rows = $table.bootstrapTable('getSelections');
            if ($rows.length ==0) {
                layer.msg("您还未选择，请您至少选择一个!");
            }else {
                var ids = $.map($rows, function (row) {
                    return row.id;
                    alert(row.id);
                    ids.push(row.id)
                })

                zzpUtils.confirm("您将删除选择的数据", function (index) {
                    zzpUtils.action({
                        url: "/wmsartificialreplenishment/delete",
                        data: JSON.stringify({ids:ids}),
                        success: function (data) {
                            setTimeout(function () {
                                layer.msg(data.title);
                            }, 500);
                            zzpUtils.refreshTable("#table");
                        }, error: function (xhr, textStatus) {
                            console.log(textStatus);
                            console.log(xhr)
                        }
                    });
                });
            }
        })  ;// 多选删除结束

        var $table = zzpUtils.table({
            elem: '#table',
            isApi: true,
            pagination: true,
            url: '/wmsartificialreplenishment/list',
            columns: [{
                field: '',
                checkbox: true
            }, {
                field: 'bh',
                title: '补货编号'
            }, {
                field: 'cjsj',
                title: '创建时间'
            }, {
                field: 'cjr',
                title: '创建人'
            },{
                field: 'scsj',
                title: '生成时间'
            },{
                field: 'qrsj',
                title: '确认时间'
            }, {
                field: 'zt',
                title: '状态'
            }, {
                field: 'show_zt',
                title: '生成状态'
            },  {
                field: 'caozuo',
                title: '操作',
                events: operateEvent,
                formatter: operateFormatter
            }],
            queryParams: function () {//查询条件
                return zzpUtils.getFormJson($("#searchForm"));
            },
            detailFormatter: function (index, row) {
                return "这里就没有确定过11";
            },
            onDblClickRow:function ( row,index) {/*双击行展示详情*/
                btn_cha(row.id);
            }
        });

        /*表格右侧按钮*/
        function operateFormatter(value, row, index) {
            return [
                '<a class="layui-btn layui-btn-xs" id="editRow">查看明细</a>',
                '<a class="layui-btn layui-btn-xs" id="editRow">查看补货任务</a>',
             /*   '<a class="layui-btn layui-btn-primary layui-btn-xs" id="btn_qi"  >启用</a>',

                '<a class="layui-btn layui-btn-danger layui-btn-xs" id="btn_jin" >禁用</a>'*/
            ].join('')

        }

        //查询
        $(".inline-search-btn").on('click', function () {
            zzpUtils.refreshTable("#table");
        })
        /*新增收发类别*/
        $(".add-btn").on('click', function () {
            zzpUtils.dialog({
                title: "新增收发类别",
                type: 2,
                content: "/SendReceiveCategory/add",
                area: ['50%', '50%'], //设置dialog大小，也可以不设置，
                end: function () {//增加成功后刷新
                    zzpUtils.refreshTable("#table");
                }
            });
        })
        /*顶部按钮编辑库区*/
        $(".edit-btn").on('click', function () {
            var $rows = $table.bootstrapTable('getSelections');
            if ($rows.length == 1) {
                var ids = $.map($rows, function (row) {
                    return row.id;
                })


                    zzpUtils.dialog({
                        title: "编辑货品",
                        type: 2,
                        content: "/SendReceiveCategory/editCategory?id=" + ids,
                        area: ['50%', '50%'], //设置dialog大小，也可以不设置，
                        end: function () {//修改成功后刷新
                            zzpUtils.refreshTable("#table");
                        }
                    });
                } else {
                layer.msg("请选择一条进行编辑");
            }
        })


    });

    /*查看收发类别*/
    function cha_kuwei(id) {
        var zzpUtils = layui.zzpUtils,
            $ = layui.jquery,
            laydate = layui.laydate;
        zzpUtils.dialog({
            title: "查看收发类别",
            type: 2,
            content: "/kuqu/search_kw?id=" + id,
            area: ['60%', '60%'], //设置dialog大小，也可以不设置，
        });
    }
    /*双击查看详情*/
    function btn_cha(id){
        var zzpUtils = layui.zzpUtils,
            $ = layui.jquery,
            laydate = layui.laydate;
        zzpUtils.dialog({
            title: "收发类别详情",
            type: 2,
            content: "/SendReceiveCategory/detailCategory?id=" + id,
            area: ['65%', '65%'], //设置dialog大小，也可以不设置，
        });

    }


</script>
</html>